#pragma once
#include <string>
#include <cstddef> // std::size_t
#include <boost/date_time/posix_time/posix_time.hpp>
#include <odb/nullable.hxx>
#include <odb/core.hxx>

typedef boost::posix_time::ptime ptime;

#pragma db object
class Student
{
public:
  Student() {}
  Student(unsigned long id, unsigned long class_id, const std::string &name)
      : _id(id),
        _class_id(class_id),
        _name(name) {}

  void id(unsigned long id) { _id = id; }
  unsigned long id() { return _id; }

  void class_id(unsigned long class_id) { _class_id = class_id; }
  unsigned long class_id() { return _class_id; }

  void name(const std::string &name) { _name = name; }
  std::string name() { return _name; }

private:
  friend class odb::access;
#pragma db id
  unsigned long _id;       // 学生id
  unsigned long _class_id; // 班级id
  std::string _name;       // 学生姓名
};

#pragma db object
class Class
{
public:
  Class() {}
  Class(int class_id, const std::string &class_name)
      : _class_id(class_id),
        _class_name(class_name) {}

  void class_id(int class_id) { _class_id = class_id; }
  int class_id() { return _class_id; };

  void class_name(const std::string &class_name)
  {
    _class_name = class_name;
  }
  std::string class_name() { return _class_name; }

private:
  friend class odb::access;
#pragma db id
  int _class_id;
  std::string _class_name;
};

#pragma db view object(Student)\
                object(Class = classes : Student::_class_id == classes::_class_id) \
                query((?))
struct Student_Class
{
#pragma db column(Student::_id)
  unsigned long _id; // 学生id
#pragma db column(Student::_class_id)
  unsigned long _class_id; // 班级id
#pragma db column(Student::_name)
  std::string _name; // 学生姓名
#pragma db column(classes::_class_name)
  std::string _class_name;
};


